package com.shujia.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;

public class Demo1Test {
    public static void main(String[] args) throws IOException {

        Configuration configuration = new Configuration();

        //指定zk的连接地址
        configuration.set("hbase.zookeeper.quorum", "master:2181,node1:2181,node2:2181");

        //创建连接
        Connection connection = ConnectionFactory.createConnection(configuration);


        //获取管理员对象，可以通过这个对象创建修改删除表
        Admin admin = connection.getAdmin();

        //创建表的描述对象，指定表名
        HTableDescriptor hTableDescriptor = new HTableDescriptor(TableName.valueOf("test5"));

        //创建列簇描述对象，可以给列簇增加自定义属性
        HColumnDescriptor info = new HColumnDescriptor("info");

//        info.setMaxVersions(10);
//        info.setTimeToLive(5);

        //增加列簇
        hTableDescriptor.addFamily(info);


        //创建表
        admin.createTable(hTableDescriptor);


        //关闭连接
        connection.close();


    }
}
